//
//  ChooseViewController.m
//  CarUser
//
//  Created by 王森林 on 2018/11/29.
//  Copyright © 2018年 王森林. All rights reserved.
//

#import "ChooseViewController.h"
#import "ChooseWithBrandViewController.h"
#import "ChooseWithConditionNewViewController.h"
#import "HomeSearchViewController.h"
#import "HomeMessagePageViewController.h"
@interface ChooseViewController ()

@end

@implementation ChooseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.titleColorSelected = RGB(255, 255, 255);
    self.titleColorNormal =  RGB(195, 195, 195);
    self.titleSizeNormal = 16;
    self.showOnNavigationBar = YES;
    self.menuViewStyle  =  WMMenuViewStyleLine;
    self.progressWidth = 50;
    self.progressColor =  RGB(255, 255, 255);
    self.progressHeight = 3;
    self.progressViewCornerRadius = 5;
    self.progressViewBottomSpace = 5;
//    self.menuView.backgroundColor = [UIColor redColor];
    [super viewDidLoad];
   
    [self setNavLeftBar];
    [self setNavRightBar];
    // Do any additional setup after loading the view.
}

- (void)setNavLeftBar
{
    
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"choose_search"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(handleSearchAction)];
    
}

- (void)setNavRightBar
{
    
    
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
//    rightView.backgroundColor = [UIColor whiteColor];
    
    
    UIImage *cartImage = IMG(@"choose_cart");
//    UIButton *cartBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    cartBtn.frame = CGRectMake(50, (44-IMGHEIGHT(cartImage))/2, IMGWIDTH(cartImage), IMGHEIGHT(cartImage));
//
//    [cartBtn setImage:cartImage forState:UIControlStateNormal];
//    [cartBtn addTarget:self action:@selector(handleCartAction) forControlEvents:UIControlEventTouchUpInside];
//    [rightView addSubview:cartBtn];

    UIImage *messageImage = IMG(@"choose_message");
    UIButton *messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
//    messageBtn.frame = CGRectMake(50, (44-IMGHEIGHT(messageImage))/2, IMGWIDTH(messageImage), IMGHEIGHT(messageImage));
    
    messageBtn.frame = CGRectMake(50+IMGWIDTH(cartImage)+12, (44-IMGHEIGHT(messageImage))/2, IMGWIDTH(messageImage), IMGHEIGHT(messageImage));
    [messageBtn setImage:messageImage forState:UIControlStateNormal];
    [messageBtn addTarget:self action:@selector(handleMessageAction) forControlEvents:UIControlEventTouchUpInside];
    [rightView addSubview:messageBtn];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightView];
    

}

#pragma  mark - 进入搜索界面
- (void)handleSearchAction
{
    
    HomeSearchViewController *control = [[HomeSearchViewController alloc] init];
    control.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:control animated:YES];
}


#pragma  mark - 进入购物界面
- (void)handleCartAction
{
    
    
}

#pragma  mark - 进入消息界面
- (void)handleMessageAction
{
    HomeMessagePageViewController *control = [[HomeMessagePageViewController alloc] init];
    control.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:control animated:YES];
    
}

#pragma mark - WMPageControllerDataSource
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return 2;
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    switch (index) {
        case 0:
        {
            ChooseWithBrandViewController *control = [[ChooseWithBrandViewController alloc] init];
            return control;
        }
            break;
        case 1:
        {
            ChooseWithConditionNewViewController *control = [[ChooseWithConditionNewViewController alloc] init];
            return control;
        }
            break;
            
        default:
            return nil;
            break;
    }
 
    
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    switch (index) {
        case 0:
            return @"按品牌";
            break;
        case 1:
            return @"按条件";
            break;
            
        default:
            return @"";
            break;
    }
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView{
    //    return _contentFrame;
    
    return CGRectMake(0, 0, BOUNDWIDTH, BOUNDHEIGHT);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView{
    //    menuView.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    //    return _menuFrame;
    
    return CGRectMake((BOUNDWIDTH - 150)/2, 0, 150, 45);
}

- (void)pageController:(WMPageController *)pageController lazyLoadViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
    //    NSLog(@"%@", info);
}

- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
    //    NSLog(@"%@", info);
}


- (void)pageController:(WMPageController *)pageController didEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
    //    NSLog(@"%s", __FUNCTION__);
}

- (void)menuView:(WMMenuView *)menu didLayoutItemFrame:(WMMenuItem *)menuItem atIndex:(NSInteger)index {
    //    NSLog(@"%@", NSStringFromCGRect(menuItem.frame));
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
